package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_DaChiZi
 * Date: 2025/6/23
 * Time: 17:48
 */
public class Demo30 {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService service = Executors.newFixedThreadPool(4);

        for (int i = 0; i < 100; i++) {
            int id = i;
            service.submit(() -> {
               Thread current = Thread.currentThread();
                System.out.println(" hello thread " + id + " " +current.getName());
            });
        }
        //等待运行2s
        Thread.sleep(2000);
        //终止线程池里的线程
        service.shutdown();
    }
}
